package repository

import (
	"github.com/gofiber/fiber/v2"
	"gorm.io/gorm"
	"guns-excel/internal/app/model"
)

// 增加模型
func AddModel(ctx *fiber.Ctx, model *model.Model, db *gorm.DB) error {
	return db.Table("model").Create(&model).Error
}

// 模型列表
func GetListModel(ctx *fiber.Ctx, db *gorm.DB) ([]*model.Model, error) {
	models := make([]*model.Model, 0)
	if err := db.Table("model").Where("is_del", 0).Find(&models).Error; err != nil {
		return nil, err
	}
	return models, nil
}

func GetModelByModelId(ctx *fiber.Ctx, modelId string, db *gorm.DB) (*model.Model, error) {
	model := new(model.Model)
	if err := db.Table("model").Where("is_del = ?", 0).Where("id = ?", modelId).First(&model).Error; err != nil {
		return nil, err
	}
	return model, nil
}
